import com.pojo.Student;
import jdk.internal.module.Resources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

public class MyBatisTest {
    private SqlSessionFactory sqlSessionFactory;
    private SqlSeeion sqlSeeion;
    @Before
    public void init(){
        String resource = "mybatis-config.xml";
        Reader reader = null;
        try{
            reader = Resources.getResourceAsReader(resource);
            SqlSessionFactory sqlMapper = new
                    SqlSessionFactoryBuilder().build(reader);
            sqlSession = sqlMapper.openSession();
        } catch (IOException e){
            e.printStackTrace();
        }
    }
    @Test
    public void findAllStudentTest(){
        List<String> list =
                sqlSession.selectList("com.itheima.mapper.StudentMapper.findAllStudent");
        for(Student student : list){
            System.out.println(student);
        }
    }
    @After
    public void destroy(){
        sqlSeeion.commit();
        sqlSeeion.close();
    }
}
